<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="ftdate">
        <el-date-picker clearable
          v-model="queryParams.ftdate"
          type="month"
          value-format="yyyy-MM-dd"
          @input="handleMonthChange"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8"  style="text-align: center;font-size: 50px;"> 
        分摊统计汇总表
 </el-row>
 <el-row type="flex" justify="end">
    <el-col :span="3" style="font-size: 50px; color: red;">
      内部资料
    </el-col>
  </el-row>

    <el-row :gutter="10" class="mb8">
     
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="JyjcSharingExpensesSumList" @selection-change="handleSelectionChange" height="700">
      <el-table-column type="selection" width="30" align="center" />
      <el-table-column label="年份" fixed  width="55" align="center" prop="year" />
      <el-table-column label="月份" fixed  width="55" align="center" prop="yf" />
      <!-- <el-table-column label="部门" align="center" prop="deptname" />
      <el-table-column label="部门编码" align="center" prop="deptcode" /> -->
      <el-table-column label="经济科目"  fixed align="center" prop="jjkm" />
      <!-- <el-table-column label="包含的费用" align="center" prop="expenseType" /> -->
      <el-table-column label="总体合计"  width="120"   fixed  align="center" prop="zthj" />
      <el-table-column label="六部一所合计" width="100"   align="center" prop="lbyshj" />
      <el-table-column label="办公室(党群工作部)" width="100"   align="center" prop="bgs" />
      <el-table-column label="人力资源部" width="100"  align="center" prop="rlzy" />
      <el-table-column label="财务内审部" width="100"  align="center" prop="cw" />
      <el-table-column label="市场拓展部(业务协作部)" width="100"  align="center" prop="sctz" />
      <el-table-column label="质量管理部"  width="100" align="center" prop="zlgl" />
      <el-table-column label="设备管理部" width="100"  align="center" prop="sbgl" />
      <el-table-column label="科技规划研究所" width="100"   align="center" prop="kjghyjs" />
      <el-table-column label="专业所合计" width="100"  align="center" prop="zyshj" />
      <el-table-column label="计量科学研究所" width="100"  align="center" prop="jls" />
      <el-table-column label="标准研究所" width="100"  align="center" prop="bzs" />
      <el-table-column label="特种设备检验技术研究所" width="100"   align="center" prop="tzs" />
      <el-table-column label="产品质量检验技术研究所" width="100"   align="center" prop="cps" />
      <el-table-column label="纤维质量监测研究所" width="100"  align="center" prop="xws" />
      <el-table-column label="食品与粮食检验技术研究所" width="100"  align="center" prop="sps" />
      <el-table-column label="药品检验技术研究所" width="100"  align="center" prop="yps" />
      <el-table-column label="医疗器械检验技术研究所" width="100"  align="center" prop="yls" />
      <el-table-column label="农产品与农药土壤肥料检验技术研究所"  width="100"  align="center" prop="ncp" />
      <el-table-column label="畜牧与水产品检验技术研究所" width="100"  align="center" prop="xms" />
      <el-table-column label="能源产品检验技术研究所" width="100"  align="center" prop="nys" />
      <el-table-column label="度量衡检定所" width="100"  align="center" prop="dls" />
      <el-table-column label="职能部门分摊" width="100"   align="center" :show-overflow-tooltip="true" prop="mark1" />
      <el-table-column label="专业所独立行使事项" width="100"  align="center"  :show-overflow-tooltip="true" prop="mark2" />
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改财务收入支出统计对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="年份" prop="year">
          <el-input v-model="form.year" placeholder="请输入年份" />
        </el-form-item>
        <el-form-item label="月份" prop="yf">
          <el-input v-model="form.yf" placeholder="请输入月份" />
        </el-form-item>
        <el-form-item label="部门" prop="deptname">
          <el-input v-model="form.deptname" placeholder="请输入部门" />
        </el-form-item>
        <el-form-item label="部门编码" prop="deptcode">
          <el-input v-model="form.deptcode" placeholder="请输入部门编码" />
        </el-form-item>
        <el-form-item label="经济科目" prop="jjkm">
          <el-input v-model="form.jjkm" placeholder="请输入经济科目" />
        </el-form-item>
        <el-form-item label="总体合计" prop="zthj">
          <el-input v-model="form.zthj" placeholder="请输入总体合计" />
        </el-form-item>
        <el-form-item label="六部一所合计" prop="lbyshj">
          <el-input v-model="form.lbyshj" placeholder="请输入六部一所合计" />
        </el-form-item>
        <el-form-item label="办公室(党群工作部)" prop="bgs">
          <el-input v-model="form.bgs" placeholder="请输入办公室(党群工作部)" />
        </el-form-item>
        <el-form-item label="人力资源部" prop="rlzy">
          <el-input v-model="form.rlzy" placeholder="请输入人力资源部" />
        </el-form-item>
        <el-form-item label="财务内审部" prop="cw">
          <el-input v-model="form.cw" placeholder="请输入财务内审部" />
        </el-form-item>
        <el-form-item label="市场拓展部(业务协作部)" prop="sctz">
          <el-input v-model="form.sctz" placeholder="请输入市场拓展部(业务协作部)" />
        </el-form-item>
        <el-form-item label="质量管理部" prop="zlgl">
          <el-input v-model="form.zlgl" placeholder="请输入质量管理部" />
        </el-form-item>
        <el-form-item label="设备管理部" prop="sbgl">
          <el-input v-model="form.sbgl" placeholder="请输入设备管理部" />
        </el-form-item>
        <el-form-item label="科技规划研究所" prop="kjghyjs">
          <el-input v-model="form.kjghyjs" placeholder="请输入科技规划研究所" />
        </el-form-item>
        <el-form-item label="专业所合计" prop="zyshj">
          <el-input v-model="form.zyshj" placeholder="请输入专业所合计" />
        </el-form-item>
        <el-form-item label="计量科学研究所" prop="jls">
          <el-input v-model="form.jls" placeholder="请输入计量科学研究所" />
        </el-form-item>
        <el-form-item label="标准研究所" prop="bzs">
          <el-input v-model="form.bzs" placeholder="请输入标准研究所" />
        </el-form-item>
        <el-form-item label="特种设备检验技术研究所" prop="tzs">
          <el-input v-model="form.tzs" placeholder="请输入特种设备检验技术研究所" />
        </el-form-item>
        <el-form-item label="产品质量检验技术研究所" prop="cps">
          <el-input v-model="form.cps" placeholder="请输入产品质量检验技术研究所" />
        </el-form-item>
        <el-form-item label="纤维质量监测研究所" prop="xws">
          <el-input v-model="form.xws" placeholder="请输入纤维质量监测研究所" />
        </el-form-item>
        <el-form-item label="食品与粮食检验技术研究所" prop="sps">
          <el-input v-model="form.sps" placeholder="请输入食品与粮食检验技术研究所" />
        </el-form-item>
        <el-form-item label="药品检验技术研究所" prop="yps">
          <el-input v-model="form.yps" placeholder="请输入药品检验技术研究所" />
        </el-form-item>
        <el-form-item label="医疗器械检验技术研究所" prop="yls">
          <el-input v-model="form.yls" placeholder="请输入医疗器械检验技术研究所" />
        </el-form-item>
        <el-form-item label="农产品与农药土壤肥料检验技术研究所" prop="ncp">
          <el-input v-model="form.ncp" placeholder="请输入农产品与农药土壤肥料检验技术研究所" />
        </el-form-item>
        <el-form-item label="畜牧与水产品检验技术研究所" prop="xms">
          <el-input v-model="form.xms" placeholder="请输入畜牧与水产品检验技术研究所" />
        </el-form-item>
        <el-form-item label="能源产品检验技术研究所" prop="nys">
          <el-input v-model="form.nys" placeholder="请输入能源产品检验技术研究所" />
        </el-form-item>
        <el-form-item label="度量衡检定所" prop="dls">
          <el-input v-model="form.dls" placeholder="请输入度量衡检定所" />
        </el-form-item>
        <el-form-item label="备注1" prop="mark1">
          <el-input v-model="form.mark1" placeholder="请输入备注1" />
        </el-form-item>
        <el-form-item label="备注2" prop="mark2">
          <el-input v-model="form.mark2" placeholder="请输入备注2" />
        </el-form-item>
        <el-form-item label="排序" prop="orderNum">
          <el-input v-model="form.orderNum" placeholder="请输入排序" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listJyjcSharingExpensesSum, getJyjcSharingExpensesSum, delJyjcSharingExpensesSum, addJyjcSharingExpensesSum, updateJyjcSharingExpensesSum,alllistJyjcSharingExpensesSum } from "@/api/system/JyjcSharingExpensesSum"

export default {
  name: "JyjcSharingExpensesSum",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 财务收入支出统计表格数据
      JyjcSharingExpensesSumList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        year: null,
        yf: null,
        deptname: null,
        deptcode: null,
        jjkm: null,
        expenseType: null,
        ftdate: "",
        mark1: null,
        mark2: null,
        orderNum: null
      },
      updateflag:{
        year: "",
        yf: "",
        deptcode: "",
        flag:""
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    const query = this.$route.query;
    this.queryParams.ftdate= this.getCurrentMonth();
    this.getList()
  },
  methods: {
    /** 查询财务收入支出统计列表 */
    getList() {
      this.loading = true
      alllistJyjcSharingExpensesSum(this.queryParams).then(response => {
        this.JyjcSharingExpensesSumList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    handleMonthChange(){
      this.queryParams.pageNum = 1;
      const [y, m,d] = this.queryParams.ftdate.split('-');
      this.queryParams.year=y;
      this.queryParams.yf=m;
      this.getList()
    },
    getCurrentMonth() {
      const now = new Date()
      const year = now.getFullYear()
      const month = String(now.getMonth() + 1).padStart(2, '0')
      return `${year}-${month}`
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        year: null,
        yf: null,
        deptname: null,
        deptcode: null,
        jjkm: null,
        expenseType: null,
        zthj: null,
        lbyshj: null,
        bgs: null,
        rlzy: null,
        cw: null,
        sctz: null,
        zlgl: null,
        sbgl: null,
        kjghyjs: null,
        zyshj: null,
        jls: null,
        bzs: null,
        tzs: null,
        cps: null,
        xws: null,
        sps: null,
        yps: null,
        yls: null,
        ncp: null,
        xms: null,
        nys: null,
        dls: null,
        mark1: null,
        mark2: null,
        orderNum: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.year)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加财务收入支出统计"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const year = row.year || this.ids
      getJyjcSharingExpensesSum(year).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改财务收入支出统计"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.year != null) {
            updateJyjcSharingExpensesSum(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addJyjcSharingExpensesSum(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const years = row.year || this.ids
      this.$modal.confirm('是否确认删除财务收入支出统计编号为"' + years + '"的数据项？').then(function() {
        return delJyjcSharingExpensesSum(years)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/JyjcSharingExpensesSum/export', {
        ...this.queryParams
      }, `JyjcSharingExpensesSum_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
